package com.winit.base;

import java.sql.*;

/**
 * Created by wangjian on 17/7/5.
 */
public class BaseSelect {

    public static void selectT(Connection conn, String sql) throws Exception {
        Long start = System.currentTimeMillis();
        Integer total = 0;

        try {
            PreparedStatement ps = conn.prepareStatement(sql);
            ResultSet result = ps.executeQuery();
            while (result.next()) {
                total++;
                StringBuffer buffer = new StringBuffer();
                for (int i = 1; i <= result.getMetaData().getColumnCount(); i++) {
                    buffer.append(result.getString(i)).append("      ");
                }
                System.out.println(buffer.toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        } finally {
            Long end = System.currentTimeMillis();
            System.out.println("开始时间:" + start + ",结束时间:" + end + ".总用时:" + (end - start) + ".共" + total + "条记录");
        }
    }
}
